import 'package:dio/dio.dart';
import 'package:freemusic/model/AbstractDiss.dart';
import 'package:freemusic/model/AbstractModel.dart';
import 'package:freemusic/model/AbstractSong.dart';
import 'package:freemusic/utils/request/migu.dart';
import 'package:freemusic/utils/request/netease.dart';

import 'qq.dart';
import 'kugou.dart';

Future<List<AbstractSong>> search(
    String platform, String keyword, int page) async {
  if (keyword.isEmpty) {
    return List();
  }
  switch (platform.toLowerCase()) {
    case "kugou":
      return await KuGouAPI.search(keyword, page);
    case "qq":
      return await QQAPI.search(keyword, page);
    case "netease":
      return await NeteaseAPI.search(keyword, page);
    case "migu":
      return await MiGuAPI.search(keyword, page);
  }
  return List();
}

Future<AbstractSong> getSong(AbstractSong info) async {
  switch (info.platform.toString().toLowerCase()) {
    case "kugou":
      return await KuGouAPI.getSong(info.hash);
      break;
    case "qq":
      // QQSong qqSong = info;
      return await QQAPI.getSong(info);
    case "netease":
      return await NeteaseAPI.getSong(info);
    case "migu": 
      return await MiGuAPI.getSong(info);
  }
  return info;
}

Future<AbstractModel> getAccount( String account, String password, String platform) async {
  switch (platform.toLowerCase()) {
    case "kugou":
      break;
    case "qq":
      break;
    case "netease":
      return await NeteaseAPI.getAccount(account, password);
      break;
  }
}

Future<List<AbstractDiss>> getSongDiss(String keyword, String platform) async {
  switch (platform.toLowerCase()) {
    case "kugou":
      break;
    case "qq":
      // return await QQAPI.getSongSheet(keyword);
      break;
    case "netease":
      // return await NeteaseAPI.getSongSheet("17602135213", "950506");
      break;
  }
}

Future<Map> getDissSongs(String platform, String account, int dissId) {
  switch (platform.toLowerCase()) {
    case "kugou":
      break;
    case "qq":
      return QQAPI.getSongsByDissId(account, dissId);
      break;
    case "netease":
      break;
  }
}

Future downloadSong(String platform, String url, String savepath) async {
  switch (platform.toLowerCase()) {
    case "kugou":
      await KuGouAPI.download(url, savepath);
      break;
    case "qq":
      await QQAPI.download(url, savepath);
      break;
    case "netease":
      await NeteaseAPI.download(url, savepath);
      break;
    case "migu":
      await MiGuAPI.download(url, savepath);
  }
}

Future<Map> loadNetVersion() async {
  Dio dio = Dio();
  DateTime now = DateTime.now();
  Response response =
      await dio.get("http://www.static.jt-lee.cn/version.json?$now");
  return response.data;
}
